package v1beta1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

type FileVolumeStatusType string
type FileVolumeSubStatusType string

const (
	FileVolumeStatusReady        FileVolumeStatusType    = "Ready"
	FileVolumeStatusFailed       FileVolumeStatusType    = "Failed"
	FileVolumeStatusCreating     FileVolumeStatusType    = "Creating"
	FileVolumeStatusPending      FileVolumeStatusType    = "Pending"
	FileVolumeCreateFailed       FileVolumeStatusType    = "CreateFailed"
	FileVolumeSubStatusExpanding FileVolumeSubStatusType = "Expanding"
	FileVolumeSubStatusExpanded  FileVolumeSubStatusType = "Expanded"
	FileVolumeSubStatusFailed    FileVolumeSubStatusType = "Failed"

	FileVolumeReasonExpandFailed = "expandFailed"
	FileVolumeReasonCreateFailed = "createFailed"
)

// FileVolumeSpec defines the desired state of file volume.
type FileVolumeSpec struct {
	//+optional
	OwnerId string `json:"ownerId,omitempty"`
	// provider secret
	ProviderRef ProviderRef `json:"providerRef,omitempty"`
	// ShareProto defines share protocol of file system, support: NFS, CIFS
	ShareProto string `json:"shareProto,omitempty"`
	// SFS Turbo文件系统性能类型，包括“STANDARD”标准型和“PERFORMANCE”性能型。
	ShareType string `json:"shareType,omitempty"`
	// file volume size
	Size int32 `json:"size,omitempty"`
	// security groups define references file volume.
	SecurityGroupsRef SecurityGroupsRef `json:"securityGroupsRef,omitempty"`
	// file volume vpc references
	VPCRef           VPCRef           `json:"vpcRef,omitempty"`
	ResourceAffinity ResourceAffinity `json:"resourceAffinity,omitempty"`
	//+optional
	VolumeID string `json:"volumeId,omitempty"`
	//+optional
	NfsAllowHost string `json:"nfsAllowHost,omitempty"`
	//+optional
	CifsUserRw string `json:"cifsUserRw,omitempty"`
	//+optional
	CifsPwdRw string `json:"cifsPwdRw,omitempty"`
	//+optional
	CifsUserRo string `json:"cifsUserRo,omitempty"`
	//+optional
	CifsPwdRo string `json:"cifsPwdRo,omitempty"`
	// +optional
	OrderInfo OrderInfo `json:"orderInfo,omitempty"`
}

type SecurityGroupsRef struct {
	Name string `json:"name,omitempty"`
	ID   string `json:"id,omitempty"`
}

type VPCRef struct {
	Name      string `json:"name,omitempty"`
	Namespace string `json:"namespace,omitempty"`
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// +kubebuilder:resource:shortName=fv
// +kubebuilder:subresource:status

// AttachVolume is the Schema for the c API
type FileVolume struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              FileVolumeSpec `json:"spec,omitempty"`
	// status of AttachVolume
	Status FileVolumeStatus `json:"status,omitempty"`
}

type NetInfo struct {
	VPCId string `json:"vpcId,omitempty"`
	SubId string `json:"subId,omitempty"`
}

type FileVolumeStatus struct {
	Status  FileVolumeStatusType `json:"status,omitempty"`
	NetInfo NetInfo              `json:"netInfo,omitempty"`
	// returned volume information
	Info VolumeInfo `json:"volumeInfo,omitempty" protobuf:"bytes,5,opt,name=volumeInfo"`

	CreatingProcess string `json:"creatingProcess,omitempty"`
	// 文件系统剩余容量，单位GB。
	AvailCapacity string `json:"availCapacity,omitempty"`
	// 文件系统的挂载端点。
	ExportLocation *string `json:"exportLocation,omitempty"`
	// 文件存储扩容状态 expanding/expanded/failed
	// +optional
	SubStatus FileVolumeSubStatusType `json:"subStatus,omitempty"`
	// 文件存储实际状态
	// +optional
	Size int32 `json:"size,omitempty"`
	// +optional
	Conditions []Condition `json:"conditions,omitempty"`
	//+optional
	NfsAllowHost string `json:"nfsAllowHost,omitempty"`
	//+optional
	CifsUserRw string `json:"cifsUserRw,omitempty"`
	//+optional
	CifsPwdRw string `json:"cifsPwdRw,omitempty"`
	//+optional
	CifsUserRo string `json:"cifsUserRo,omitempty"`
	//+optional
	CifsPwdRo string `json:"cifsPwdRo,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// AttachVolumeList contains a list of AttachVolume item
type FileVolumeList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []FileVolume `json:"items"`
}
